package util;

import java.util.Date;

import utils.DateUtil;
import utils.FileUtil;

public class LogUtil {

	private static boolean FLAG = false;
	private static String PATH = null;
	private static String LINE = null;
	private static String SIGN = "portal";

	static {
		if ("linux".equalsIgnoreCase(System.getProperty("os.name"))) {
			PATH = "/usr/logs/" + SIGN;
			LINE = "\n";
			FLAG = false;
		} else {
			PATH = "c:/logs/" + SIGN;
			LINE = "\r\n";
			FLAG = true;
		}
	}

	public static void log(String type, String name, String info) {
		if (FLAG) {
			System.out.println(info);
		}
		String filePath = PATH + "/" + type + "/";
		String fileName = name;
		String fileInfo = DateUtil.format(new Date(), "HHmmss") + " " + info + LINE;
		try {
			FileUtil.append(filePath, fileName, fileInfo);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("logging failure");
		}
	}

	public static void entrance(String info) {
		log("entrance", DateUtil.format(new Date(), "yyyy_MM_dd"), info);
	}
	
	public static void transport(String info) {
		log("transport", DateUtil.format(new Date(), "yyyy_MM_dd"), info);
	}

	public static void main(String[] args) {
		entrance("333");
	}

}
